package com.example.myui.activity;

import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;

import com.example.myui.MainActivity;
import com.example.myui.R;
import com.example.myui.utils.NotifyUtil;
import com.example.myui.utils.NotifyUtils;


public class NotifyUtilActivity extends AppCompatActivity {
    private Context mContext;
    private String TAG = NotifyUtilActivity.class.getSimpleName();
    private int progress = 0;
    private NotifyUtil util = null;
    private boolean toggle = true;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mContext = this;
        util = new NotifyUtil(mContext);
        setContentView(R.layout.activity_notify_utils);
        findViewById(R.id.button1).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Log.i(TAG, "onClick: ");
//                notifyUtils.notify_normal_singline(null, R.mipmap.ic_launcher,
//                        "ticker", "he", "content", false, false, false);
                NotifyUtils notifyUtils = new NotifyUtils(mContext, 1);
                util.creatNotify(R.mipmap.ic_launcher,
                        R.mipmap.ic_launcher, "title1", "text1", "第一个通知", null, 1, 0);

                util.updateNotify(1, 0);
            }
        });

        findViewById(R.id.button2).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
//                Notification.Builder builder = new Notification.Builder(mContext);
//                builder.setTicker("ticker");
//                builder.setContentText("context");
//                builder.setContentTitle("text");
//                builder.setSmallIcon(R.mipmap.ic_launcher);
//                builder.setWhen(System.currentTimeMillis());
//                builder.setProgress(100, 10, false);
//                builder.setAutoCancel(true);
//                Intent intent = new Intent(mContext, MainActivity.class);
//                PendingIntent activity = PendingIntent.getActivity(mContext, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
//                builder.setContentIntent(activity);
//
//                NotificationManager manager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
//                manager.notify(2, builder.build());

                util.creatNotify(R.mipmap.ic_launcher, R.mipmap.ic_launcher,
                        "title2",
                        "text2",
                        "第二个通知",
                        null,
                        2,
                        0);

                util.updateNotify(2, 20);
            }
        });

        findViewById(R.id.button3).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                util.creatNotify(R.mipmap.ic_launcher, R.mipmap.ic_launcher,
                        "title3",
                        "text3",
                        "第二个通知",
                        null,
                        3,
                        0);

                util.updateNotify(3, progress);
                progress += 10;
            }
        });

        findViewById(R.id.button4).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                int notifycationNum = util.getMap().size();
                Log.i(TAG, "notifycationNum: " + notifycationNum);
//                util.cancelNotify(3);
            }
        });

        findViewById(R.id.button5).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                int size = util.getMap().size();
                for (int i = 0; i < size; i++) {
                    util.cancelNotify(i + 1);
                }
            }
        });
    }
}
